package com.luoran.car.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.UrlResource;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.MimeMessageHelper;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import javax.mail.MessagingException;
import javax.mail.internet.MimeMessage;
import java.net.MalformedURLException;
 
@Service
public class EmailService {
 
    @Resource
    private JavaMailSender mailSender;
    @Value("${spring.mail.username}")
    private String from;
 
    /**
     * 发送附件到邮箱
     * @param to             邮箱地址
     * @param subject        邮件主题
     * @param text           内容
//     * @param attachmentName 附件名称
//     * @param attachmentUrl  附件地址
     * @throws MessagingException
     * @throws MalformedURLException
     */
    public void sendEmailWithAttachment(String to, String subject, String text) throws MessagingException {
        MimeMessage message = mailSender.createMimeMessage();
        MimeMessageHelper helper = new MimeMessageHelper(message, true);
        helper.setFrom(from);
        helper.setTo(to);
        helper.setSubject(subject);
        helper.setText(text);
        mailSender.send(message);
    }

}